log using "pela Table 1.smcl", replace
clear
use "pela data replication file.dta"

** democratic satisfaction

label define loser 1 "Not a Member of President's Party" 0 "Member of President's Party", replace
label values loser loser

mixed dem_sat C.v2x_polyarchy loser wt_grow female age edu || pais: || country_year: loser
mixed dem_sat C.v2x_polyarchy##C.loser wt_grow female age edu || pais: || country_year: loser
quietly: margins , at(v2x_poly=(0.15(.05).95) loser=(0(1)1) wt_grow=(3.8) female=(0) age=(48) edu=(4)) level(95)
marginsplot, recast(line) recastci(rline) xtitle( "Level of Democracy (V-Dem)") ytitle("Predicted Democratic Satisfaction") title("Satisfaction with Democracy") ciopts(lpattern(dash) lcolor(gs8)) ci2opts(lpattern(dash)) scheme(s1mono) plot2opts(lpattern(line) lcolor(black)) plotopts(lpattern(line) lcolor(gs8)) legend(rows(2))
graph save "Graph" "figure 2 democratic satisfaction.gph", replace

** trust electoal agency

mixed trust_electoral_agency  C.v2x_polyarchy loser wt_grow female age edu|| pais: || country_year: loser
mixed trust_electoral_agency C.v2x_polyarchy##C.loser wt_grow female age edu|| pais: || country_year: loser
quietly: margins , at(v2x_poly=(0.15(.05).95) loser=(0(1)1) wt_grow=(3.8) female=(0) age=(48) edu=(4)) level(95)
marginsplot, recast(line) recastci(rline) xtitle( "Level of Democracy (V-Dem)") ytitle("Predicted Democratic Satisfaction") title("Satisfaction with Democracy") ciopts(lpattern(dash) lcolor(gs8)) ci2opts(lpattern(dash)) scheme(s1mono) plot2opts(lpattern(line) lcolor(black)) plotopts(lpattern(line) lcolor(gs8)) legend(rows(2))
graph save "Graph" "figure 2 trust in election agency.gph", replace

** confidence elections

mixed confidence_elections_past1  C.v2x_polyarchy loser wt_grow female age edu || pais: || country_year: loser
mixed confidence_elections_past1 C.v2x_polyarchy##C.loser wt_grow female age edu || pais: || country_year: loser
quietly: margins , at(v2x_poly=(0.15(.05).95) loser=(0(1)1) wt_grow=(3.8) female=(0) age=(48) edu=(4)) level(95)
marginsplot, recast(line) recastci(rline) xtitle( "Level of Democracy (V-Dem)") ytitle("Predicted Democratic Satisfaction") title("Satisfaction with Democracy") ciopts(lpattern(dash) lcolor(gs8)) ci2opts(lpattern(dash)) scheme(s1mono) plot2opts(lpattern(line) lcolor(black)) plotopts(lpattern(line) lcolor(gs8)) legend(rows(2))
graph save "Graph" " figure 2 confidence elections predictions.gph", replace

**note that for the graph's Y axis labels I labeled them by hand using the values in Appendix 1. 

log close
